/*
 * Copyright (c) 2016- 2020 qolome.com Inc. All Rights Reserved.
 * ProjectName: qolome-knowledge
 * FileName: ConcretePrototype.java
 * Author: jiangfeng@qolome.com
 * Date: 2020/3/1 下午3:54
 * LastModified: 2020/03/01 15:36:01
 */

package com.qolome.knowledge.design.pattern.prototype.deep;


import lombok.Data;

import java.io.*;
import java.util.List;

/**
 * @author Qolome
 * @version V1.0
 * @Description 深克隆
 * @date 2020年 03月01日 15:32:08
 */

@Data
public class ConcretePrototype  implements Serializable{

    private static final long serialVersionUID = 6648246432377648691L;
    private int age;
    private String name;
    List<String> hobbies;

    public ConcretePrototype deepClone() throws IOException, ClassNotFoundException {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(bos);
        oos.writeObject(this);
        ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
        ObjectInputStream ois = new ObjectInputStream(bis);
        return (ConcretePrototype)ois.readObject();
    }
}
